/*****************************************************************************************
 **  Author:jxx 2022
 **  QQ:283591387
 **完整文档见：http://v2.volcore.xyz/document/api 【代码生成页面ViewGrid】
 **常用示例见：http://v2.volcore.xyz/document/vueDev
 **后台操作见：http://v2.volcore.xyz/document/netCoreDev
 *****************************************************************************************/
//此js文件是用来自定义扩展业务代码，可以扩展一些自定义页面或者重新配置生成的代码
import gridHeader from "@/components/print/selectTemplet.vue"
let extension = {
  components: {
    //查询界面扩展组件
    gridHeader,
    gridBody: '',
    gridFooter: '',
    //新建、编辑弹出框扩展组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  tableAction: '', //指定某张表的权限(这里填写表名,默认不用填写)
  buttons: {
    view: [],
    box: [],
    detail: []
  }, //扩展的按钮
  methods: {
    //下面这些方法可以保留也可以删除
    onInit() {
      // this.textInline = false //增加这个会导致第一个选择框换行
      this.detailOptions.textInline = false
      this.rowKey = "WHSE_Id"
      this.single = true;
      this.queryFields = ['WHSE_no', 'WHSE_name', 'Cat_pid']

    },
    async onInited() {
      // this.setFiexdSearchForm(true);
      // this.buttons.forEach(item => {
      //   if (item.name == "高级查询") {
      //     item.hidden = true
      //   }
      // })
      // this.searchFormFields.Cat_pid=['17f016e3-ece3-4c3e-a266-9bacdaa7bb21', 'e836e1b6-bb12-4e64-91ba-a42d6c140cd9']
      if (this.$route.path != "/q_warehouse") {
        this.setFiexdSearchForm(true);
        this.height = 550 - 150;
        this.buttons.forEach(item => {
          if (item.value != "Search") {
            item.hidden = true
          }
        })
      }
      if (this.$route.path == "/q_warehouse" && JSON.stringify(this.$route.query) != '{}') {
        console.log("触发查询")
        await this.base.setSearchParamFn(this)
        // this.searchFormFields.WHSE_no = null
        // this.searchFormFields.WHSE_name = null
        // this.searchFormFields.Cat_pid = null
        // const selectList = ['Cat_pid',]
        // this.searchFormOptions.forEach(item => {
        //   item.forEach(x => {
        //     if (selectList.includes(x.field)) {
        //       x.onChange = (v) => {
        //         this.$route.query = {}
        //       }
        //     }
        //   })
        // })
        setTimeout(() => {
          this.refresh()
        })
      }
    },
    loadTreeChildren(tree, treeNode, resolve) {
      let url = `api/q_warehouse/getTreeTableChildrenData?class_Id=${tree.WHSE_Id}`;
      this.http.post(url, {}).then((result) => {
        resolve(result.rows);
      });
    },
    async searchBefore(param) {
      console.log(this.searchFormFields,"['17f016e3-ece3-4c3e-a266-9bacdaa7bb21', 'e836e1b6-bb12-4e64-91ba-a42d6c140cd9']")
      //界面查询前,可以给param.wheres添加查询参数
      //返回false，则不会执行查询
      if (param.wheres.length == 0) {
        param.value = 1
      }
      if (this.$route.path == "/q_warehouse" && JSON.stringify(this.$route.query) != '{}') {
        await this.base.setSearchBefore(this, "WHSE_Id", param)
        // if (this.searchFormFields.WHSE_no ||this.searchFormFields.WHSE_name ) {
        //    param.wheres=param.wheres.filter(item=>item.name!="WHSE_Id")
        //   this.$route.query = {}
        // }
      }
      return true;
    },
    searchAfter(result) {
      //查询后，result返回的查询数据,可以在显示到表格前处理表格的值
      return true;
    },
    addBefore(formData) {
      //新建保存前formData为对象，包括明细表，可以给给表单设置值，自己输出看formData的值
      return true;
    },
    addAfter(result) { //新建保存后result返回的状态及表单对象
      this.initDicKeys()
      return true; //返回false不会关闭弹出框
    },
    updateBefore(formData) {
      //编辑保存前formData为对象，包括明细表、删除行的Id
      return true;
    },
    updateAfter(result) { //编辑保存后result返回的状态及表单对象
      this.initDicKeys()
      return true; //返回false不会关闭弹出框
    },
    rowClick({
      row,
      column,
      event
    }) {
      //查询界面点击行事件
      this.$refs.table.$refs.table.toggleRowSelection(row); //单击行时选中当前行;
    },
    async modelOpenBefore(row) {
      this.CreateUserBoole = row.CreateID == this.$store.state.userID
      this.rowAuditStatus = await row.AuditStatus
      if (JSON.stringify(row) == "{}") {
        this.rowAuditStatus = 0
        this.CreateUserBoole = true
      }
    },
    modelOpenAfter(row) {
      if (this.$route.path != "/q_warehouse" || this.rowAuditStatus != 0) { // || !this.CreateUserBoole
        this.boxButtons[0].hidden = true
      } else {
        this.boxButtons[0].hidden = false

      }
      this.editFormOptions.forEach(item => {
        item.forEach(x => {
          if (this.$route.path != "/q_warehouse" || this.rowAuditStatus != 0) { //|| !this.CreateUserBoole
            x.disabled = true
          } else {
            // if (x.field == "WHSE_no") {
            //   x.disabled = true
            // } else {
            x.disabled = false
            // }
            if (this.$route.path != "/q_warehouse") {
              x.disabled = true
            }
          }

        })
      })
    }
  }
};
export default extension;